<?php
    class Action extends CI_Model{
        function __construct(){
            // Call the Model constructor
            parent::__construct();
        }

        public function getList($controllerId = null){        
            $select = "SELECT * FROM actions 
                JOIN controllers ON controllers.controller_id = actions.controller_id
                JOIN action_types  ON action_types.action_type_id = actions.action_type_id";
            
            if(!empty($controllerId)){
                $select .= " WHERE controllers.controller_id = ".$controllerId;
            }    
            
            $select .= " ORDER BY controllers.controller_name, action_types.action_type_name";
            $query = $this->db->query($select);
            return $query->result();
        }
        
        public function fetchPairs(){
            $array = array();
            $list = $this->getList();
            foreach($list as $item){
                $array[$item->action_id] = $item->action_type_name;
            }
            return $array;
        }
    }  
?>